import { ObjectId } from 'mongodb'

export enum UserStatus {
  Normal = 1,
  Disabled = 2
}

export enum Identity {
  Admin = 1, // 系统管理员
  Official = 2, // 官方用户
  Student = 3 // 学生用户
}

export enum Relevance {
  Collect = 0, // 收藏
  Focusme = 1, // 关注我的
  Myfocus = 2, // 我关注的
  Mythumb = 3, // 我点赞的
  Myissue = 4, // 我发布的
  Mycars = 5, // 我的购物车 #下单后删除/直接删除数据库
  Dingdan = 6, // 我的订单 #只要下单就是
  Goumai = 7, // 我的购买 #在确认订单后生效
  Maichu = 8, // 我卖出去的 #在确认订单后生效
  Remark = 9,
  likeRemark = 10, // 点赞的评论
  Mycared = 11 // 购物车结束后的状态
}

// 通知的类型
export enum AdvicesType {
  Maichuing = 1, // 你需要去送货的东西
  Cancel = 2, // 订单取消了,不用送货了
  Arrival = 3, // 货物已经送到了
  Empty = 3 // 没货了
}

export enum DingdanStat {
  Queren = 1, // 确认收货
  Cancel = 2, // 取消订单
  Waiting = 3, // 运输中
  Daohuo = 4, // 到货
  Empty = 5 // 缺货
}

export enum Gender {
  male = 1, // 男
  female = 2, // 女
  null = 3 // 未知
}

export interface Token {
  userId: ObjectId
  userToken: string
  createdAt: Date
}

export interface IUser {
  _id: ObjectId
  username: string
  password: string
  nickname: string
  avatar: string
  gender: Gender
  qqnumber: number
  registerTime: number
  mdb: number // 民大币
  role: Identity // 角色身份
  state: UserStatus
  major: string[] // 专业
  signature: string
  islove: boolean
}

export interface IBooks {
  _id?: ObjectId
  publisher: ObjectId
  title: string
  content: string
  banner: string[]
  lowprice: number
  allstock: number
  books: {
    bookname: string
    price: number
    stock: number
  }[]
  tags: string[]

  createAt: number
  updateAt: number
  views: number
  isDelete: boolean
  putaway: boolean

  judger: ObjectId // 通过他来判断是不是等待审核呗,没有他就是等待审核
  judgeCon: string
}

// 书籍下面的评论 按照赞同数量排序
export interface Remark {
  _id?: ObjectId
  userId: ObjectId
  bookId: ObjectId
  content: string
  rate: number
  thumbs: number
  createAt: number
  islove?: boolean
  isDelete: boolean
}

// 订单列表
export interface Dingdan {
  _id?: ObjectId
  userId: ObjectId // 购买人
  cartIds: ObjectId[]
  name: string
  address: string
  allprice: number
  phone: number
  note: string
  createAt: number
  isDelete: boolean

  books?: IBooks[]
  cart?: { _id: ObjectId; destId: ObjectId }
}

export interface Connect {
  _id?: ObjectId
  userId: ObjectId
  destId: ObjectId
  time: number
  type: Relevance

  // 购物车专有属性
  allprice?: number
  names?: string[]
  prices?: number[]
  indexs?: number[]
  confirm?: DingdanStat // 是否确认了收货
  book?: {
    _id: ObjectId
  }
}

// 通知表
export interface Advices {
  _id?: ObjectId
  userId: ObjectId // 卖家
  destId: ObjectId // 订单id
  cartId: ObjectId // 购物车ids
  bookId: ObjectId // 书籍ids
  time: number
  seen: boolean
  type: AdvicesType
}

export interface Dynamic {
  createAt: number
  type: Relevance
  dynamic: IUser | IBooks | Remark | IBooks[]
}
